package sanshui.system.trade.util;

import com.sun.org.apache.xpath.internal.operations.Bool;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class ZhangDieUtil {
    /*
    * his: 0：时间最远
    *
    * */
    public static Boolean maxZhangDieFu(List<BigDecimal> his, int num, BigDecimal fudu){
        if (his.size() < num){
            return false;
        }

        List<BigDecimal> targetList = his.subList(his.size()-num, his.size());

        BigDecimal max = targetList.stream().max(BigDecimal::compareTo).get();
        BigDecimal min = targetList.stream().min(BigDecimal::compareTo).get();

        return max.multiply(BigDecimal.valueOf(100)).divide(min, 3, RoundingMode.HALF_UP).subtract(BigDecimal.valueOf(100)).compareTo(fudu) <= 0;
    }

    public static Boolean hasZhangTing(List<BigDecimal> his, int numData, int numZT){
        if (his.size() < numData){
            return false;
        }
        List<BigDecimal> targetList = his.subList(his.size()-numData, his.size());

        int index = 0;
        for (BigDecimal change : targetList) {
            if (change.compareTo(BigDecimal.valueOf(9.9)) >= 0){
                index++;
                if (index >= numZT){
                    return true;
                }
            }
        }
        return false;
    }


    public static void main(String[] args) {
        List<BigDecimal> his = new ArrayList<>();
        his.add(BigDecimal.valueOf(10));
        his.add(BigDecimal.valueOf(1));
        his.add(BigDecimal.valueOf(5));
        his.add(BigDecimal.valueOf(3));

        ZhangDieUtil.maxZhangDieFu(his, 4, BigDecimal.valueOf(20));
    }
}
